﻿using MoviesWeb.BLL;
using MoviesWeb.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_admininf : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataToRepeater();
        }
    }
    private void BindDataToRepeater()
    {
        Repeater1.DataSource = ManagerBLL.GetManagerList();
        Repeater1.DataBind();
    }
    protected void Bt_present_Click(object sender, EventArgs e)
    {
        if (hide_id.Value == "")
        {
            if (ManagerBLL.Add(new Manager()
             {
                 Mn_account = login_id.Text.Trim(),
                 Mn_password = login_pwd.Text.Trim()
             }))
            {
               // Response.Write("<script> ShowMessage('添加成功!','添加提示')</script>");
                Response.Write("<script>alert('添加成功!')  </script>");
                BindDataToRepeater();
            }
            else
                Response.Write("<script>alert('添加失败!')  </script>");
                //Response.Write("<script> ShowMessage('添加失败!','添加提示')</script>");
        }
        else
        {
            if (ManagerBLL.Changepwd(login_id.Text.Trim(), login_oldpwd.Text.Trim(), login_pwd.Text.Trim(), Convert.ToInt32(hide_id.Value)))
            {
                Response.Write("<script>alert('修改成功!')  </script>");
               // Response.Write("<script> ShowMessage('修改成功!','修改提示')</script>");
                BindDataToRepeater();
            }
            else
                Response.Write("<script>alert('修改失败!')  </script>");
               // Response.Write("<script> ShowMessage('修改失败!','修改提示')</script>");
            hide_id.Value = "";
        }
    }
    protected void Bt_delete_Click(object sender, EventArgs e)
    {
        var su = 0;
        var er = 0;
        foreach( RepeaterItem item  in  Repeater1.Items)
        {
             var  del_id=(item.FindControl("CheckBoxid") as  CheckBox);
             if (del_id.Checked)
             {
                 if (ManagerBLL.Remove(Convert.ToInt32(del_id.Attributes["value"])))
                     su++;
                 else
                     er++;
             }
        }
        BindDataToRepeater();
        Response.Write("<script>alert('删除成功" + su + "条,失败" + er + "条','删除提示')  </script>");
       // Response.Write("<script> ShowMessage('删除成功" + su + "条,失败" + er + "条','删除提示')</script>");
    }
}